1 04-03-24 (Wednesday)

Dear Heavenly Father,
We start this day asking for your joy and strength in this moment when we are practicing these programming skills.
Please let this be a moment of true fellowship and character building in our community of learning.
Be with us in any difficulties we face. Give us a disposition to help, and humility to be helped.
Give us wisdom to discern your beauty and justice as we write these Python programs.
May everything we do and learn here be offered to you in praise, gratitude and service to our neighbors.
In Jesus name we pray. Amen.

2 POGIL Activity - Files

Click here to access the file.

3 Operating Systems

  • The first computers usually were very big and expensive, so universities and companies usually had only one. Because of that, someone had to be there to coordinate the execution of the programs and maintain the computer working — i.e., the operator.
  • At some point, people decided to write software that could handle all of these tasks automatically. This resulted in the invention of the operating system (OS): “a program that automatically manages the hardware, netowrk, and energy resources of a computer, maximizing speed and enabling multitasking.”
    • This also gave rise to the new wave of personal computers (PC) at the 1970’s, which people could buy and operate at home - using OSs such as Amiga or MS-DOS.
    • You can check a more detailed history at this very interesting article.
  • Today, OSs have many functions to help you operate the many devices, peripherals and programs in your PC. Among its main components are:
    • Kernel: The core component of the operating system that manages the system’s resources, such as CPU, memory, and devices.
    • Process Management: Manages the execution of processes or tasks within the operating system. It includes functions like process scheduling, creation, termination, and communication between processes.
      • For example, when you open Thonny, it is a process! And the Python program you run in Thonny too.
      • You may know how to access Windows’ Process Manager: CTRL+ALT+DEL…
    • Memory Management: Manages the system’s memory resources, including allocating memory to processes, ensuring memory protection, and handling memory swapping or paging.
    • Device Drivers: Software components that allow the operating system to communicate with hardware devices, such as printers, keyboards, and graphics cards. Device drivers facilitate the interaction between the operating system and hardware components.
    • Security: Ensures the integrity, confidentiality, and availability of the system and its resources. This includes user authentication, access control, data encryption, and protection against malware and other security threats.
    • User Interface: Provides a way for users to interact with the operating system. This can include graphical user interfaces (GUIs), command-line interfaces (CLIs), or a combination of both.
      • For example, GNOME and KDE are Linux’s common used user interfaces.
    • File System: Manages how data is stored, organized, and retrieved on storage devices, such as hard drives and solid-state drives. It provides a hierarchical structure for files and directories, and it ensures data integrity and security.
      • For example, you may have get used to the “files and folders” metaphor, but some older OSs used different ideas: Amiga, for example, organized data in form of “drawers and projects”.

3.1 The os module in Python

In Python, you can interact with the operating system of your PC using the os module. This module provides a way to perform various operating system-related tasks such as:

  1. File and Directory Operations: You can create, delete, move, and rename files and directories using functions like os.mkdir(), os.rmdir(), os.rename(), etc.

  2. Process Management: You can start new processes, get information about existing processes, and manage process IDs using functions like os.system(), os.spawn(), os.kill(), etc.

  3. Environment Variables: You can access and modify environment variables using functions like os.getenv() and os.putenv().

  4. Working Directory: You can get and change the current working directory using functions like os.getcwd() and os.chdir().

  5. Path Manipulation: You can manipulate file paths using functions like os.path.join(), os.path.basename(), os.path.dirname(), etc.

  6. Permissions: You can set and get permissions of files and directories using functions like os.chmod(), os.access(), etc.

  7. Other Operations: You can perform other miscellaneous operations such as checking file existence (os.path.exists()), file size (os.path.getsize()), etc.

Keep in mind that some of these operations might require elevated user permissions depending on the operating system and the specific action being performed.

3.2 Trying some examples

  • Write a program to print the current folder where your program is running
  • Create a new folder
  • Get your program’s process ID number — use os.getpid()
  • Make a infinite while loop, run your program, get its ID number and kill it in the process manager!